package com.swyc.osschat.Test.jiajiemi.base64;

import com.swyc.osschat.Common.Util.Decode.Base64;
import com.swyc.osschat.Common.Util.Decode.Base64Utils;

import java.io.UnsupportedEncodingException;

/**
 * @description TODO
 * @Author: z156940l@outlook.com
 * @className Tste
 * @Date: 2023/3/21 15:46
 */
public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {
        // base64加解密文字
        strHandle();
        // base64图片处理
        picHandle();
    }

    private static void strHandle()throws UnsupportedEncodingException{
        String str = "这是一段测试文字";
        byte[] data = str.getBytes();
        String encodeStr = Base64.encode(data);
        System.out.println("这是编码后的文字：" + encodeStr);
        byte[] bytes = Base64.decode(encodeStr);
        String decodeStr = new String(bytes, "UTF-8");
        System.out.println("这是解密后的文字：" + decodeStr);
    }

    private static void picHandle()throws UnsupportedEncodingException{
        // 本地图片地址
        String localPicAddress = "D:/迅雷下载/跑车.jpeg";
        // 网络图片地址
        String netPicAddress = "http://cdn-hw-static.shanhutech.cn/bizhi/staticwp/202208/e5593bb85db4d662257727bf1ff41e0e--64028494.jpg";

        String str1 = Base64Utils.ImageToBase64ByLocal(localPicAddress);
        System.out.println("str1" + str1);

        String str2 = Base64Utils.ImageToBase64ByOnline(netPicAddress);
        System.out.println("str2:" + str2);

        Base64Utils.Base64ToImage(str1, "C:/Users/Administrator/Desktop/跑车.jpeg");
        Base64Utils.Base64ToImage(str2, "C:/Users/Administrator/Desktop/在线.jpg");
    }
}
